from typing import Optional

from pydantic import BaseModel, Field
from sqlalchemy import Column, String, BigInteger, Text
from toollib.utils.now2timestamp_ import now2timestamp

from app.datatype import DeclBase, filter_fields


class ModelConfig(DeclBase):
    __tablename__ = "model_config"

    #自增主键
    id = Column(BigInteger, primary_key=True, autoincrement=True, comment="主键")
    model_name = Column(Text,  comment="模型名")
    model_url = Column(Text, comment="模型地址")
    model_api_key = Column(Text,  comment="模型密钥")
    model_type = Column(BigInteger, default=0, comment="模型类型 1.大模型 2.ocr")
    #删除状态
    is_deleted = Column(BigInteger, default=0, comment="删除状态，0.未删除，1.已删除")


class ModelConfigListMdl(BaseModel):

    #自增主键
    id : Optional[int] = Field(default=0, description="主键ID")
    model_name:  Optional[str] = Field( default="",  description="模型名")
    model_url:  Optional[str] = Field(default="", description="模型地址")
    model_api_key :  Optional[str] = Field(default="", description="模型密钥")
    model_type:  Optional[int] = Field(default=0, description="模型类型 1.大模型 2.ocr")
    #删除状态
    is_deleted :  Optional[int] = Field(default=0, description="删除状态，0.未删除，1.已删除")

    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls,
            exclude=[]
        )

class ModelConfigGet(BaseModel):
    #删除状态
    # is_deleted : int = Field(default=0, description="删除状态，0.未删除，1.已删除")

    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls,
            exclude=[]
        )
class CodeAuthorizationMdl(BaseModel):

    authorization_code: Optional[str] = Field(default="", description="授权码")
    private_key: Optional[str] = Field(default="", description="私钥")


    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls,
            exclude=[]
        )
